package hip.util;

/**
 * @author Loanin
 * @date 2014年6月24日
 * @describe 计算数据消耗
 */
public class CostUtil {

    private long begin;

    private long end;

    public CostUtil() {
        begin = System.nanoTime();
    }

    public void end() {
        end = System.nanoTime();
    }

    public long getCost() {
        if (end == 0)
            end = System.nanoTime();
        long cost = (end - begin) / 1000000;
        begin = System.nanoTime();// 重新计时
        return cost;
    }


    public static void main(String[] args) throws InterruptedException {
        CostUtil a = new CostUtil();
        Thread.sleep(2);
        System.out.println(a.getCost());
    }

}
